Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Pyomo Model Plot #2251

Closed
wants to merge 5 commits into from
Closed

[WIP] Pyomo Model Plot #2251

wants to merge 5 commits into from

Conversation

michaelbynum
Copy link
Contributor

Summary/Motivation:

This PR adds a function to create a Plotly plot of the graph of a pyomo model. It is "interactive" in the sense that you get information about a component if you hover over the corresponding node.

Legal Acknowledgement

By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution:

  1. I agree my contributions are submitted under the BSD license.
  2. I represent I am authorized to make the contributions and grant the license. If my employer has rights to intellectual property that includes these contributions, I represent that I have received permission to make contributions and grant the required license on behalf of that employer.

@codecov
Copy link

codecov bot commented Jan 12, 2022

Codecov Report

Merging #2251 (782ea93) into main (dbd4fae) will increase coverage by 0.01%.
The diff coverage is 96.34%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2251      +/-   ##
==========================================
+ Coverage   83.07%   83.09%   +0.01%     
==========================================
  Files         607      608       +1     
  Lines       77018    77100      +82     
==========================================
+ Hits        63984    64063      +79     
- Misses      13034    13037       +3     
Flag Coverage Δ
linux 80.37% <96.34%> (+0.01%) ⬆️
osx 70.69% <96.34%> (+0.01%) ⬆️
other 80.34% <96.34%> (+0.01%) ⬆️
win 77.48% <96.34%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pyomo/util/graph.py 96.34% <96.34%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dbd4fae...782ea93. Read the comment docs.

Copy link
Member

@blnicho blnicho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really neat!

Comment on lines +1 to +3
import networkx as nx
import pyomo.environ as pe
import plotly.graph_objects as go
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the attempt_import stuff around networkx and plotly here?

@@ -201,6 +201,7 @@ def _print_deps(self, deplist):
'ipython', # contrib.viewer
'matplotlib',
'networkx', # network, incidence_analysis, community_detection
'plotly', # pyomo.util.graph.plot_pyomo_model
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep this list in alphabetical order

Comment on lines +27 to +29
def graph_from_pyomo(m: _BlockData,
include_objective: bool = True,
active: bool = True) -> nx.Graph:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a short docstring?

Comment on lines +49 to +54
def plot_pyomo_model(m: _BlockData,
include_objective: bool = True,
active: bool = True,
plot_title: Optional[str] = None,
bipartite_plot: bool = False,
show_plot: bool = True):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a short docstring?

@blnicho
Copy link
Member

blnicho commented Jan 20, 2022

There was some discussion at the developers meeting about whether this belongs in pyomo.util or pyomo.contrib. There is some concern about introducing yet another implementation of "Pyomo model --> graph representation" functionality and a strong desire to develop a common solution for this that could be shared by this plotting utility, pyomo.contrib.community_detection, and pyomo.contrib.incidence_analysis.

@blnicho
Copy link
Member

blnicho commented Feb 13, 2023

Closing this for now. This PR inspired some great discussion around standardizing graph representations of Pyomo models in #2272 but we don't currently have the resources to get those ideas implemented in this PR like we wanted. This plotting functionality has been incorporated in pyomo.contrib.incidence_analysis in PR #2716.

@blnicho blnicho closed this Feb 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants